using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using sbMembership.Library.Presenters;

namespace Tests.sbMembership.ListUsers
{
    [TestFixture]
    public class ListUsersTest
    {
        private MockListUsersView mockView;
        private ListUsersPresenter presenter;
        private bool addUserEventRaised = false;
        private bool assignRoleToUserEventRaised = false;
        private bool deleteUserEventRaised = false;

        [TestFixtureSetUp]
        public void Setup()
        {
            mockView = new MockListUsersView();
            presenter = new ListUsersPresenter(mockView);
            mockView.AttachPresenter(presenter);
        }

        [Test]
        public void InitView()
        {
            presenter.InitViewFor(ListUsersPresenter.ActionEnum.none);
            Assert.IsNotEmpty(mockView.Users);
            Assert.IsNotEmpty(mockView.Message);
        }

        [Test]
        public void AddUserRaisesEvent()
        {
            presenter.LaunchAddUserEvent += new EventHandler(OnAddUserEvent);
            presenter.LaunchAddUser();
            Assert.IsTrue(addUserEventRaised);
        }

        void OnAddUserEvent(object sender, EventArgs e)
        {
            addUserEventRaised = true;
        }

        [Test]
        public void AssignUserToRoleRaisesEvent()
        {
            presenter.LaunchAssignRoleToUserEvent += new EventHandler(OnAssignUserToRoleEvent);
            presenter.LaunchAssignRoleToUser(TestSetup.testUserName);
            Assert.IsTrue(assignRoleToUserEventRaised);
        }

        void OnAssignUserToRoleEvent(object sender, EventArgs e)
        {
            assignRoleToUserEventRaised = true;
        }

        [Test]
        public void DeleteUser()
        {
            presenter.DeleteUserCompleteEvent += new EventHandler(OnDeleteUserCompleteEvent);
            presenter.DeleteUser(TestSetup.testDeleteUserName);
            Assert.IsTrue(deleteUserEventRaised);
        }

        void OnDeleteUserCompleteEvent(object sender, EventArgs e)
        {
            deleteUserEventRaised = true;
        }

    }
}
